//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		pagedata: {},
		articles:[],
		fenleis:[],
		products:[],
		productfenleis:[],
		nodatapic_close:true,
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (){
		var the=this;
		the.setData({
			pagedata: [],
			menu:menu,
			root:app.setting.att_url
		});
		the.articles();
		the.fenleis();
		the.products();
		the.productfenleis();
	},
	articles: function(){
		var the = this
		app.util.request({
			'data':{'plugin':'core','action':'article.list','num':18},
			'success':function(result){
				console.log(result);
						if(result.list){
							for (var i = 0; i < result.list.length; i++) {
								result.list[i].url = encodeURIComponent(result.list[i].url);
							}
							the.setData({
								articles: result.list,
							});
						}else{
							//获取会话失败
							var message={
									'title':'获取会话失败',
									'content':result,
							};
							wx.showModal(message);
						}
			}
		});
	},
	fenleis: function(){
		var the = this
		app.util.request({
			'data':{'plugin':'core','action':'article.list'},
			'success':function(result){
				console.log(result);
						if(result.fenlei){
							for (var i = 0; i < result.fenlei.length; i++) {
								result.fenlei[i].url = encodeURIComponent(result.fenlei[i].url);
							}
							the.setData({
								fenleis: result.fenlei,
							});
						}else{
							//获取会话失败
							var message={
									'title':'获取会话失败',
									'content':result,
							};
							wx.showModal(message);
						}
			}
		});
	},
	products: function(){
		var the = this
		app.util.request({
			'data':{'plugin':'core','action':'product.list','num':20},
			'success':function(result){
				console.log(result);
						if(result.list){
							for (var i = 0; i < result.list.length; i++) {
								result.list[i].url = encodeURIComponent(result.list[i].url);
							}
							the.setData({
								products: result.list,
							});
						}else{
							//获取会话失败
							var message={
									'title':'获取会话失败',
									'content':result,
							};
							wx.showModal(message);
						}
			}
		});
	},
	productfenleis: function(){
		var the = this
		app.util.request({
			'data':{'plugin':'core','action':'product.list','num':20},
			'success':function(result){
				console.log(result);
						if(result.fenlei){
							for (var i = 0; i < result.fenlei.length; i++) {
								result.fenlei[i].url = encodeURIComponent(result.fenlei[i].url);
							}
							the.setData({
								productfenleis: result.fenlei,
							});
						}else{
							//获取会话失败
							var message={
									'title':'获取会话失败',
									'content':result,
							};
							wx.showModal(message);
						}
			}
		});
	},
	onShareAppMessage: function (res) {
		var the = this
		var pagedata = the.data.pagedata
		if (res.from === 'button') {
		}
		var path=the.data.route+'?'+app.access.query;
		if(app.access.op){
			path +='&op='+app.access.op;
		}
		if(pagedata.fromuser){
			path +='&fromuser='+pagedata.fromuser;
		}
		return {
		  title: the.data.pagetitle,
		  path: path,
		  desc: app.setting.sharedesc,
		  success: function(res) {
		  },
		  fail: function(res) {
		  }
		}
	}
});